<template>
  <section class="user-avatar-container">
    <nuxt-link class="user-avatar" :to="'/user/' + userData.userId + '?name=' + userData.name">
      <img :src="userData.avatar" alt="">
    </nuxt-link>
    <div class="dropdown">
      <nuxt-link :to="'/user/' + userData.userId">
        个人中心
      </nuxt-link>
      <nuxt-link to="/user/settings/profile">
        个人资料
      </nuxt-link>
      <nuxt-link to="/tempArticle">
        草稿箱
      </nuxt-link>
      <a @click="toSignOut">
        退出登录
      </a>
    </div>
  </section>
</template>

<script>
export default {
  computed: {
    userData() {
      return this.$store.state.user.userData
    }
  },
  methods: {
    toSignOut() {
      // 移除用户数据
      this.$store.commit('removeUserDataMutation')
      this.$router.push('/')
    }
  }
}
</script>

<style scoped lang="scss">
@import "~@/assets/css/public";
.user-avatar-container {
  width: 70px;
  height: 70px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  line-height: normal;

  .user-avatar {
    width: 42px;
    height: 42px;
    overflow: hidden;
    border-radius: 42px;

    img {
      @include inner-img;
    }
  }

  &:hover .dropdown {
    display: block;
  }

  .dropdown {
    z-index: 5000;
    position: absolute;
    right: 0;
    top: 70px;
    width: 100px;
    display: none;
    background: #fff;
    border: 1px solid $theme-color-border;

    a {
      display: block;
      line-height: 50px;
      text-align: center;
      font-size: 14px;
      transition: $theme-transition;

      &:hover {
        background: $theme-color-background;
        color: $theme-color;
      }
    }
  }
}
</style>
